package com.yx.study.leet.primary.sort;

/**
 * @Classname FirstBadVersion
 * @Date 2023/01/15 20:52
 * @Author by yx
 * @Description : 第一个错误的版本-二分查找
 * https://leetcode.cn/leetbook/read/top-interview-questions-easy/xnto1s/
 */
public class FirstBadVersion {
    public int firstBadVersion(int n) {
        int start = 1, end = n;
        while (start < end) {
            int mid = start + (end - start) / 2;
            if (!isBadVersion(mid)) {
                start = mid + 1;
            } else {
                end = mid;
            }
        }
        return start;
    }

    private boolean isBadVersion(int version){
        // 此方法为LeetCode提供,此处仅为处理报错
        return true;
    }
}
